import pandas as pd
import os
import numpy as np

input_data_path = "ae.train"
processed_data_path = 'ae_train_process_data.data'
test_speaker_num = (30, 30, 30, 30, 30, 30, 30, 30, 30)
input_data_path = "ae.test"
processed_data_path = 'ae_test_process_data.data'
test_speaker_num = (31, 35, 88, 44, 29, 24, 40, 50, 29)
def process_data(input_data_path,processed_data_pathtest_speaker_num):
    file = open(input_data_path, 'r')
    write_file = open(processed_data_path, 'w')
    data = file.readlines()
    count_num = 1
    count_bank = 0
    count_bank_num = 0
    column_num = 0
    temp = []
    matrix_speak_pre = []
    write_file.writelines("c1,c2,c3,c4,c5,q1,q2,q3,q4,q5,q6,q7,q8,q9,q10,q11,q12,y\n")
    for i in list(range(len(data))):
        if data[i] == "\n":
            matrix_speak = np.mat(matrix_speak_pre)
            matrix_speak_transpose = np.transpose(matrix_speak)
            line = str(np.linalg.matrix_rank(matrix_speak)) + "," + str(column_num) + ',' + \
                str(np.linalg.norm(matrix_speak, ord=1)) + ',' + str(np.linalg.norm(matrix_speak, ord=2)) + ',' + str(
                np.linalg.norm(matrix_speak, ord=np.inf))
            temp_array = [np.array(matrix_speak_transpose[i]).sum() for i in
                          list(range(len(matrix_speak_transpose)))]
            for column_c in temp_array:
                line = line + ',' + str(column_c)
            line += ',' + str(count_bank_num + 1) + '\n'
            write_file.writelines(line)
            temp.append(np.linalg.norm(matrix_speak, ord=np.inf))
            matrix_speak_pre = []
            count_bank += 1
            column_num = 0
            continue
        else:
            column_num += 1
        if count_bank == test_speaker_num[count_bank_num]:
            count_bank_num += 1
            count_bank = 0
            count_num += 1
            temp = []
        data[i] = data[i].replace("\n", "").strip(" ")
        data[i] = data[i].replace(" ", ",")
        matrix_speak_pre.append(list(map(float, data[i].split(','))))

    file.close()
    write_file.close()
